package com.shyroke.cool.service.boke.impl;

import com.shyroke.cool.bean.ArticlePO;
import com.shyroke.cool.bean.PageDTO;
import com.shyroke.cool.mapper.ArticlePOMapper;
import com.shyroke.cool.service.ArticleService;
import com.shyroke.cool.utils.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 类名 ：
 * 用法 ： 文章服务实现类
 * 创建人 ： shyroke
 * 时间：2018/8/3 15:01
 */
@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticlePOMapper articleMapper;

    @Override
    public List<ArticlePO> getArticleList(PageDTO page, String labelID) {

        int pageNo = page.getPageNo();
        int pageSize = page.getPageSize();

        int beginIndex =  (pageSize * (pageNo - 1));
        int endIndex = pageSize * pageNo;

        List<ArticlePO> articlePOList = articleMapper.getArticleList(beginIndex,endIndex,labelID);

        //将时间格式转为yyyy-MM-dd HH:mm:ss
        articlePOList = articlePOList.stream().map(dto->{
            dto.setShowCreateTime(CommonUtil.covertDateStrFormObj(dto.getCreateTime()));
            return dto;
        }).collect(Collectors.toList());

        return articlePOList;
    }
}
